overview
Many programs need to save and/or access information from permanent devices, usually hard
disks. File I/O statements and intrinsics built in to the language create, access,
manipulate, and close files. More elaborate I/O functions are easily built from
these capabilities - the standard library contains many.
file number
Programs refer to a specific file by means of the file number returned by OPEN(). Until a file has been opened, programs
cannot access its contents.
file pointer
A file pointer variable is maintained for every open file. It points to a byte
location within the file. When a file is opened, its file pointer is initialized to
zero. When a file is read or written, the file pointer is advanced to the byte after
the data read or written. Since the file pointer is a byte offset from the beginning
of the file, the first byte of a file is at file position zero. The file position
intrinsics are:
name
meaning returns
EOF() End of
file TRUE if file pointer past last byte
POF() Position of
file File pointer
LOF() Length of
file Number of bytes (position of last byte)
SEEK() Move file
pointer Moves file pointer to specified offset
OPEN
Files must be opened by OPEN() before their contents
can be accessed. OPEN() takes two arguments, the name of the file, and an open
mode. The mode determines whether the file is open for reading, writing, or
both. It also specifies non-standard behavior such as opening a fresh version of the
file for writing (delete any existing copies and start with an empty file), versus work
with the existing contents.
$$RD Open file for reading only
$$WR Open file for writing only
$$RW Open file for reading and writing
$$WRNEW Open file for writing only (delete existing)
$$RWNEW Open file for reading and writing (delete existing)
$$RDSHARE Open file for reading only - other programs can also open the
file
$$WRSHARE Open file for writing only - other programs can also open the
file
$$RWSHARE Open file for reading and writing - other programs can open
the file
OPEN() returns an XLONG filenumber. All other file operations contain a filenumber argument to identify the file to operate on. File numbers, not file names, are the key to accessing opened files.
CLOSE
CLOSE() complements OPEN(). CLOSE() closes a file
and releases its filenumber.